package com.ticket.sass.admin.dto.input.coupons;

import com.ticket.sass.admin.annotation.ActivateTimeRange;
import com.ticket.sass.admin.annotation.WeekTimeRange;
import com.ticket.sass.admin.dto.input.WeekTimeInput;
import com.ticket.sass.admin.validator.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * @author ywb
 * @date 2024-03-15 14:36
 */
@Data
@ApiModel
@WeekTimeRange
@ActivateTimeRange
public class CouponAddInput {
    @NotBlank(message = "券名称不能为空")
    @ApiModelProperty(value = "券名称")
    private String name;
    
    @NotNull(message = "劵类型不能为空")
    @InEnum(intValues = {1, 2, 3})
    @ApiModelProperty(value = "券类型：1 抵扣券，2 满减券，3 折扣券")
    private Short type;
    
    @ApiModelProperty(value = "优惠值：抵扣券 - 忽略，满减券 - 表示金额，折扣券 - 表示折扣")
    private BigDecimal value = new BigDecimal("0.0");
    
    @ApiModelProperty(value = "门槛值：抵扣券 - 忽略，满减券 - 表示满多少可用，折扣券 - 表示满多少可用")
    private BigDecimal thresholdValue = new BigDecimal("0.0");
    
    @NotNull(message = "使用场景不能为空")
    @InEnum(intValues = {1, 2, 3})
    @ApiModelProperty(value = "使用场景：1 影票，2 卖品 3拼单影票")
    private Short scene;
    
    @NotNull(message = "生效类型不能为空")
    @InEnum(intValues = {1, 2})
    @ApiModelProperty(value = "生效类型：1 指定日期范围，2 领取后指定")
    private Short activateType;
    
    @ApiModelProperty(value = "可用开始日期（生效类型=1 时使用）")
    private LocalDate startDate;
    
    @ApiModelProperty(value = "可用结束日期（生效类型=1 时使用）")
    private LocalDate endDate;
    
    @ApiModelProperty(value = "领取后 N 天开始生效，0 表示立即生效（生效类型=2 时使用）")
    private Integer activateStart;
    
    @ApiModelProperty(value = "生效后 N 天内有效，-1 表示可用日期内有效（生效类型=2 时使用）")
    private Integer activateEnd;
    
    @NotNull(message = "可用时段类型不能为空")
    @InEnum(intValues = {0, 1})
    @ApiModelProperty(value = "可用时段：0 不限制，1 指定范围")
    private Short availablePeriod;
    
    @Valid
    @ApiModelProperty(value = "星期时间数据")
    private List<WeekTimeInput> weekTimes;
    
//    @ApiModelProperty(value = "是否允许会员卡支付时使用")
//    private Boolean allowCard = Boolean.TRUE;
    
    @ApiModelProperty(value = "会员卡禁用")
    private Boolean memberCardDisabled;
    
    @ApiModelProperty(value = "仅限新用户")
    private Boolean newUserOnly = Boolean.TRUE;
    
    @ApiModelProperty(value = "使用说明")
    private String desc;
    
    @ApiModelProperty(value = "卖品ID")
    private List<Long> commodityIds;
    
    @ApiModelProperty(value = "影片ID")
    private List<Long> filmIds;
    
    @ApiModelProperty(value = "影厅ID")
    private List<Long> hallIds;
    
    @AssertTrue(message = "优惠值必须为空")
    public boolean isValueEmpty() {
        return type != 1 || !Objects.nonNull(value);
    }
    
    @AssertTrue(message = "优惠值不能为空")
    public boolean isValueNotEmpty() {
        return type == 1 || !Objects.isNull(value);
    }
    
    @AssertTrue(message = "门槛值必须为空")
    public boolean isThresholdValueEmpty() {
        return type != 1 || !Objects.nonNull(thresholdValue);
    }
    
    @AssertTrue(message = "门槛值不能为空")
    public boolean isThresholdValueNotEmpty() {
        return type == 1 || !Objects.isNull(thresholdValue);
    }
}
